﻿using Inventory.Business.API;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Inventory.Business.DomainObjects;

namespace Inventory.Test
{
    /// <summary>
    ///This is a test class for WorkingItemsTest and is intended
    ///to contain all WorkingItemsTest Unit Tests
    ///</summary>
    [TestClass()]
    public class WorkingItemsTest
    {
     //   private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
       // public TestContext TestContext
        //{
        //    get
        //    {
        //        return testContextInstance;
        //    }
        //    set
        //    {
        //        testContextInstance = value;
        //    }
        //}

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for Save
        ///</summary>
        [TestMethod()]
        public void ChangeNameTest()
        {
            var wi = new WorkingItems();


            var list = wi.GetWorkingItems(null);

            if (list == null || list.Count == 0)
                return;

            var item = wi.GetById(list[0].ID);

            item.Name = item.Name + "-!";
            item.Code = item.Code + "-1201";
            item.SubCategoryId = 11111;

            var result = wi.ChangeName(item);
            var i = wi.GetById(item.ID);

            Assert.IsTrue(result);
            Assert.IsNotNull(i);
            Assert.AreEqual(i.ID, item.ID);
            Assert.AreEqual(i.Name, item.Name);
            Assert.AreNotEqual(i.Code, item.Code);
            Assert.AreNotEqual(i.SubCategoryId, item.SubCategoryId);
        }

        [TestMethod()]
        public void SaveTest()
        {
            var wi = new WorkingItems();

            var sub = wi.GetWorkingItemSubCategory(null);
            if (sub == null || sub.Count == 0)
                return;

            var item = new WorkingItem()
            {
                Code = sub[0].FullCode + "-1201",
                Name = "test",
                SubCategoryId = sub[0].ID
            };

            var result = wi.Create(item);
            var i = wi.GetById(item.ID);

            Assert.IsTrue(result);
            Assert.IsNotNull(i);
            Assert.AreEqual(i.ID, item.ID);
            Assert.AreEqual(i.Name, item.Name);
            Assert.AreEqual(i.Code, item.Code);
        }

        /// <summary>
        ///A test for GetById
        ///</summary>
        [TestMethod()]
        public void GetByIdTest()
        {
            var wi = new WorkingItems();

            var list = wi.GetWorkingItems(null);

            if (list == null || list.Count == 0)
                return;

            var item = wi.GetById(list[0].ID);

            Assert.IsNotNull(item);
            Assert.AreEqual(list[0].ID, item.ID);
            Assert.AreEqual(list[0].Name, item.Name);
            Assert.AreEqual(list[0].Code, item.Code);
        }
    }
}
